<%@page contentType="text/html; charset=UTF-8" session="false" %>
<%@include  file="/WEB-INF/jspf/import.jspf"%>
<%
    String command = request.getParameter("command");
    request.setAttribute("command", command);
    String picSource = request.getParameter("picSource");
    request.setAttribute("picSource", picSource);
    String perShow = request.getParameter("perShow");
    request.setAttribute("perShow", perShow);
    String showHref = request.getParameter("showHref");
    request.setAttribute("showHref", showHref);
%>

<script>
    //图片上传
    var isPic = false;
    UPC.init({upcPath:"${UPCROOT}" , application:"${appName}",command:['${command}'],windowname:1});
    function uploadSinglePic(name) {
        var cxt='${cxt}'
        if(!isPic) {
            alert("图片格式必须为 JPG,JPEG,GIF,BMP,PNG!");
            return;
        }
        $("#contractMsg").append("<font color='blue'>正在上传,请等待...</font>");
        UPC.post({
            url:'/upload_quick.jsp', 
            data:{keepSrc:"no",waterMark:0},
            file:[String(name)],
            complete:function(json) {
                if(json.retCode == 0) {
                    var fls = json.files;
                    var hrefUrl = $('#${showHref}').attr("href");
                    $('#${showHref}').attr("href",hrefUrl+fls[0].url);
                    $('#${picSource}').val(fls[0].url); 
                    $("#${perShow}").html("<img src='"+fls[0].url+"' width='63' height='48'>");
                    $("#contractMsg").html("<font color='green'>上传图片已成功!</font>");
                    //$("#upload").attr("onclick","");
                    $.pdialog.closeCurrent();
                } else {
                    $("#contractMsg").html("<font color='red'>服务器忙,请稍候再试.("+UPC.retCodeResult(Number(json.retCode))+")</font>");
                }
			
            }
		
        });
    }

    function checkImageFile(idx){
        var filename = new String($("#"+idx).val()).toUpperCase();
        if(filename=="") {
            $("#contractMsg").append("请选择一个图片文件");
            isPic = false;
            return;
        }
        if(filename.indexOf(".GIF")==-1 && filename.indexOf(".JPG")==-1 
            && filename.indexOf(".JPEG")==-1 && filename.indexOf(".BMP")==-1&& filename.indexOf(".PNG")==-1){
            $(filename).val();
            $("#contractMsg").append("请选择一个图片文件");
            isPic = false;
            return;
        }
        isPic = true;
    }
   
	
</script>  
<div class="pageContent">
    <form  id="contractForm" name="contractForm" method="post" target="hidden_frame" >
        <div style="" class="pageFormContent" layouth="56">
            <p>
                <input type="file" id="contractFile" name="file"  onchange="checkImageFile('contractFile')">
            </p>
            <p>
                <input type="button" id="upload" value="上传文件" onclick="uploadSinglePic('contractFile')">
            </p>
            <p>
                <font color="black">请上传不超过2MB的JPG,JPEG,GIF,BMP,PNG文件</font>
            </p>
            <p>
                <span style="color:red" id="contractMsg"></span>
            </p>
        </div>
        <div class="formBar">
            <ul>
                <li><div class="button"><div class="buttonContent"><button type="button" class="close">关闭</button></div></div></li>
            </ul>
        </div>
    </form>
</div>
